//
//		Nick the chatbot by :
//			Meisno
//
//		ChatBot Admin Mod plugin made by:
//			meisno

Plugin = { }
Plugin.Name = "ChatBot AM"
Plugin.Info = "Administrate your server with nick!"
Plugin.Usage = "Chat Commands"

-- DISCLAIMER: Miss Functional Function Shit below this line,
-- so i am fixing it here:

Plugin.First = function()
	local function PlayerFind( pl, target )
		local person = ChatBot.FindPlayer( target )
		return person
	end
	
	local _ChatPrefix = "$";
	
	if not _ChatCommands then
		_ChatCommands = { }
	end

	local function ChatBotAddCommand( txt, func )
		_ChatCommands[ _ChatPrefix .. txt ] = func;
	end

	hook.Add( "PlayerSay", "ChatBot.Command.Caller", function( ply, text, toall )

		local tab = string.Explode( " ", text );
		local func = _ChatCommands[ tab[1] ];
			
		if ( func ) then

			local c = tab[1];
			table.remove( tab, 1 )
			
			func( ply, c, tab  );
		
			return "";
		
			
		end

	end );

	-- Kick Function
	-- Usage: $kick <name> <reason>

	ChatBotAddCommand("kick", function(ply, cmd, args)
		local kicked = PlayerFind( ply, args[1])
		if kicked then
			if ply:IsAdmin() then
				kicked:Kick(tostring(args[2]))
				ChatBot.Reply( nil ,"Kicked " .. kicked:Nick() )
			end
		end
	end)

	-- Ban Function
	-- Usage: $ban <name> <time> <reason>

	ChatBotAddCommand("ban", function(ply, cmd, args)
		local Banned = PlayerFind( ply, args[1])
		if Banned then
			if ply:IsAdmin() then
				Banned:Ban(tonumber(args[2]), tostring(args[3]))
				Banned:Kick(tostring(args[3]))
				if args[3] == nil then
					args[3] = "N/A"
				end
				ChatBot.Reply( nil ,"banned " .. Banned:Nick() .. " with the reason: " .. tostring(args[3]))
			end
		end
	end)

	-- bring Function
	-- Usage: $bring <name>

	ChatBotAddCommand("bring", function(ply, cmd, args)
		local player1 = PlayerFind(ply, args[1])
		if player1 then
			if ply:IsAdmin() then
				player1:SetPos(ply:GetPos() + Vector(0,25,25))
			end
		end
	end)

	-- Freeze Function
	-- Usage: $freeze <name>

	ChatBotAddCommand("freeze", function(ply, cmd, args)
		local player1 = PlayerFind( ply, args[1])
		if player1 then
			if ply:IsAdmin() then
				player1:Freeze( true )
				ChatBot.Reply( nil ,"Frozen player " .. player1:Nick())
			end
		end
	end)

	-- Unfreeze Function
	-- Usage: $unfreeze <name>

	ChatBotAddCommand("unfreeze", function(ply, cmd, args)
		local player2 = PlayerFind( ply, args[1])
		if player2 then
			if ply:IsAdmin() then
				player2:Freeze( false )
				ChatBot.Reply( nil ,"UnFrozen player " .. player2:Nick())
			end
		end
	end)

	-- God Function
	-- Usage: $god <name>

	ChatBotAddCommand("god", function(ply, cmd, args)
		local godded = PlayerFind( ply, args[1])
		if godded then
			if ply:IsAdmin() then
				godded:GodEnable()
				ChatBot.Reply( nil ,"Godded " .. godded:Nick())
			end
		end
	end)

	-- UnGod Function
	-- Usage: $ungod <name>

	ChatBotAddCommand("ungod", function(ply, cmd, args)
		local godded = PlayerFind( ply, args[1])
		if godded then
			if ply:IsAdmin() then
				godded:GodDisable()
				ChatBot.Reply( nil ,"ungodded " .. godded:Nick())
			end
		end
	end)

	-- Goto Function
	-- Usage: $goto <name>

	ChatBotAddCommand("goto", function(ply, cmd, args)
		local player2 = PlayerFind( ply, args[1])
		if player2 then
			ply:SetPos(player2:GetPos() + Vector(0,25,25))
		end
	end)

	-- Slay Function
	-- Usage: $slay <name>

	ChatBotAddCommand("slay", function(ply, cmd, args)
		local slayed = PlayerFind( ply, args[1])
		if slayed then
			if ply:IsAdmin() then
				slayed:Kill()
				ChatBot.Reply( nil ,"Slayed " .. slayed:Nick())
			end
		end
	end)

	-- SSlay Function
	-- Usage: $sslay <name>

	ChatBotAddCommand("sslay", function(ply, cmd, args)
		local Sslayed = PlayerFind( ply, args[1])
		if Sslayed then
			if ply:IsAdmin() then
				Sslayed:KillSilent()
				ChatBot.Reply( nil ,"Silently Slayed " .. Sslayed:Nick())
			end
		end
	end)
end


Plugin.Second = function()
	Msg("\t Loaded Succesfully! \n")
end
